package com.zzyweb.rentalcarsys.controller;

import com.zzyweb.rentalcarsys.entity.Menu;
import com.zzyweb.rentalcarsys.service.MenuService;
import com.zzyweb.rentalcarsys.utils.ResponseObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhiyi
 * @date 10/9/25
 **/
@RestController
@RequestMapping("/menu")
@CrossOrigin
public class MenuController {
    @Autowired
    MenuService menuService;
    @GetMapping("/all")
    public ResponseObject getAll() {
        return ResponseObject.ok(menuService.getAll());
    }
    @PostMapping("/add")
    public ResponseObject addMenu(@RequestBody Menu menu) {
        menuService.addMenu(menu);
        return ResponseObject.ok();
    }
    @PutMapping("/modify")
    public ResponseObject modifyMenu(@RequestBody Menu menu) {
        menuService.modifyMenu(menu);
        return ResponseObject.ok();
    }
    @DeleteMapping("/delete/{menuId}")
    public ResponseObject deleteMenu(@PathVariable Integer menuId) {
        menuService.deleteMenu(menuId);
        return  ResponseObject.ok();
    }
    @GetMapping("/getByUsername")
    public ResponseObject getMenusByUsername(@RequestParam String username) {
        List<Menu> menusByUsername = menuService.getMenusByUsername(username);
        return ResponseObject.ok(menusByUsername);
    }
}
